home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-11-24 | 1.3 KB | 49 lines | [TEXT/PICN] |
- ############################################################################
- #
- # textcount.icn
- #
- # This program tabulates the number of characters, "words", and
- # lines in a file, and gives the lengths of the longest and shortest lines.
- # The user is prompted with a Get File dialog and the program continues to
- # process files until the user selects Cancel.
- #
- ############################################################################
-
- procedure main()
- local chars, words, lines, name, infile, max, min, line
-
- while name := getfile("File?") do {
- close(\infile)
- infile := open(name) | {
- write(&errout,"*** cannot open ",name)
- next
- }
- chars := words := lines := 0
- max := 0
- min := 2 ^ 30 # larger than possible line length
-
- while line := read(infile) do {
- max <:= *line
- min >:= *line
- lines +:= 1
- chars +:= *line + 1
- line ? while tab(upto(&letters)) do {
- words +:= 1
- tab(many(&letters))
- }
- }
-
- if min = 2 ^ 30 then
- write("empty file")
- else {
- write("number of lines: ",right(lines,8))
- write("number of words: ",right(words,8))
- write("number of characters:",right(chars,8))
- write()
- write("longest line: ",right(max,8))
- write("shortest line: ",right(min,8))
- }
- }
-
- end
-